package com.zou.lotterylucky.utils

import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.IBinder
import android.os.RemoteException
import android.os.SystemClock
import android.widget.Toast
import com.elvishew.xlog.XLog
import com.zou.lotterylucky.Constants
import com.zou.lotterylucky.LotteryApp
import com.zou.lotterylucky.activity.MySection
import com.zou.lotterylucky.data.DealEntity
import com.zou.lotterylucky.data.Order
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import woyou.aidlservice.jiuiv5.ICallback
import woyou.aidlservice.jiuiv5.IWoyouService
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit

class AidlUtil private constructor() {

    private var woyouService: IWoyouService? = null

    //    private var context: Context? = null
    lateinit var context: Context

    val isConnect: Boolean
        get() = woyouService != null

    private val connService = object : ServiceConnection {

        override fun onServiceDisconnected(name: ComponentName) {
            woyouService = null
        }

        override fun onServiceConnected(name: ComponentName, service: IBinder) {
            woyouService = IWoyouService.Stub.asInterface(service)
        }
    }

    /**
     * 设置打印浓度
     */
    private val darkness =
        intArrayOf(
            0x0600,
            0x0500,
            0x0400,
            0x0300,
            0x0200,
            0x0100,
            0,
            0xffff,
            0xfeff,
            0xfdff,
            0xfcff,
            0xfbff,
            0xfaff
        )

    /**
     * 连接服务
     *
     * @param context context
     */
    fun connectPrinterService(context: Context) {
        XLog.e(context)
        this.context = context.applicationContext
        val intent = Intent()
        intent.setPackage(SERVICE_PACKAGE)
        intent.action = SERVICE_ACTION
        context.applicationContext.startService(intent)
        context.applicationContext.bindService(intent, connService, Context.BIND_AUTO_CREATE)
    }

    /**
     * 断开服务
     *
     * @param context context
     */
    fun disconnectPrinterService(context: Context) {
        if (woyouService != null) {
            context.applicationContext.unbindService(connService)
            woyouService = null
        }
    }

    fun generateCB(printerCallback: PrinterCallback): ICallback {
        return object : ICallback.Stub() {


            @Throws(RemoteException::class)
            override fun onRunResult(isSuccess: Boolean) {

            }

            @Throws(RemoteException::class)
            override fun onReturnString(result: String) {
                printerCallback.onReturnString(result)
            }

            @Throws(RemoteException::class)
            override fun onRaiseException(code: Int, msg: String) {

            }

            @Throws(RemoteException::class)
            override fun onPrintResult(code: Int, msg: String) {

            }
        }
    }

    fun setDarkness(index: Int) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        val k = darkness[index]
        try {
            woyouService!!.sendRAWData(ESCUtil.setPrinterDarkness(k), null)
            woyouService!!.printerSelfChecking(null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    /**
     * 取得打印机系统信息，放在list中
     *
     * @return list
     */
    fun getPrinterInfo(
        printerCallback1: PrinterCallback,
        printerCallback2: PrinterCallback
    ): List<String>? {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return null
        }

        val info = ArrayList<String>()
        try {
            woyouService!!.getPrintedLength(generateCB(printerCallback1))
            woyouService!!.getPrinterFactory(generateCB(printerCallback2))
            info.add(woyouService!!.printerSerialNo)
            info.add(woyouService!!.printerModal)
            info.add(woyouService!!.printerVersion)
            info.add(printerCallback1.result)
            info.add(printerCallback2.result)
            //info.add(woyouService.getServiceVersion());
            val packageManager = context.packageManager
            try {
                val packageInfo = packageManager.getPackageInfo(SERVICE_PACKAGE, 0)
                if (packageInfo != null) {
                    info.add(packageInfo.versionName)
                    info.add(packageInfo.versionCode.toString() + "")
                } else {
                    info.add("")
                    info.add("")
                }
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }

        } catch (e: RemoteException) {
            e.printStackTrace()
        }

        return info
    }

    /**
     * 初始化打印机
     */
    fun initPrinter() {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            woyouService!!.printerInit(null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    /**
     * 打印二维码
     */
    fun printQr(data: String, modulesize: Int, errorlevel: Int) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }


        try {
            woyouService!!.setAlignment(1, null)
            woyouService!!.printQRCode(data, modulesize, errorlevel, null)
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    /**
     * 打印条形码
     */
    fun printBarCode(data: String, symbology: Int, height: Int, width: Int, textposition: Int) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }


        try {
            woyouService!!.printBarCode(data, symbology, height, width, textposition, null)
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }
    }

    /**
     * 打印文字
     */
    fun printText(content: String, size: Float, isBold: Boolean, isUnderLine: Boolean) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            if (isBold) {
                woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
            } else {
                woyouService!!.sendRAWData(ESCUtil.boldOff(), null)
            }

            if (isUnderLine) {
                woyouService!!.sendRAWData(ESCUtil.underlineWithOneDotWidthOn(), null)
            } else {
                woyouService!!.sendRAWData(ESCUtil.underlineOff(), null)
            }

            woyouService!!.printTextWithFont(content, null, size, null)
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    /*
     *打印图片
     */
    fun printBitmap(bitmap: Bitmap) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            woyouService!!.setAlignment(1, null)
            woyouService!!.printBitmap(bitmap, null)
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }


    /**
     * 打印图片和文字按照指定排列顺序
     */
    fun printBitmap(bitmap: Bitmap, orientation: Int) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开！", Toast.LENGTH_LONG).show()
            return
        }

        try {
            if (orientation == 0) {
                woyouService!!.printBitmap(bitmap, null)
                woyouService!!.printText("横向排列\n", null)
                woyouService!!.printBitmap(bitmap, null)
                woyouService!!.printText("横向排列\n", null)
            } else {
                woyouService!!.printBitmap(bitmap, null)
                woyouService!!.printText("\n纵向排列\n", null)
                woyouService!!.printBitmap(bitmap, null)
                woyouService!!.printText("\n纵向排列\n", null)
            }
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    /* */

    /**
     * 打印表格
     *//*
    public void printTable(LinkedList<TableItem> list) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show();
            return;
        }

        try {
            for (TableItem tableItem : list) {
                Log.i("kaltin", "printTable: " + tableItem.getText()[0] + tableItem.getText()[1] + tableItem.getText()[2]);
                woyouService.printColumnsString(tableItem.getText(), tableItem.getWidth(), tableItem.getAlign(), null);
            }
            woyouService.lineWrap(3, null);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
*/
    /*
     * 空打三行！
     */
    fun print3Line() {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            woyouService!!.lineWrap(3, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }
    }

    fun sendRawData(data: ByteArray) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            woyouService!!.sendRAWData(data, null)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    fun sendRawDatabyBuffer(data: ByteArray, iCallback: ICallback) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }

        try {
            woyouService!!.enterPrinterBuffer(true)
            woyouService!!.sendRAWData(data, iCallback)
            woyouService!!.exitPrinterBufferWithCallback(true, iCallback)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }

    }

    private val riQiFormatter = SimpleDateFormat("dd-MM-yyyy").apply {
        timeZone = TimeZone.getTimeZone("GMT-4")
    }
    private val timeFormatter = SimpleDateFormat("dd-MM-yyyy/hh:mm:ss aaa", Locale.US).apply {
        timeZone = TimeZone.getTimeZone("GMT-4")
    }

    fun printATotal(
        timeNow: String,
        dataO: MutableList<MySection>,
        endTime: String,
        callback: ICallback
    ) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }
        try {
            woyouService!!.enterPrinterBuffer(true)
            woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
            woyouService!!.lineWrap(1, null)
            woyouService!!.setAlignment(1, null)
            woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
            woyouService!!.printTextWithFont(/*context.getString(R.string.shangbaozongdan)*/"Total order" + "\n",
                null,
                34f,
                null
            )
            woyouService!!.setFontSize(30f, null)
            woyouService!!.setAlignment(1, null)

            woyouService!!.printText(
                endTime + "\n", null
            )

            dataO.filter { !it.isHeader }
                .groupBy {
                    it.t.belongTo
                }.forEach {
                    woyouService!!.setFontSize(24f, null)

                    woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
                    woyouService!!.setAlignment(1, null)

                    val title = LotteryApp.getTitleSimple(it.key)
                    woyouService!!.printTextWithFont("$title\n", null, 24f, null)

                    val data = it.value.map { it.t }

                    woyouService!!.setFontSize(18f, null)
                    woyouService!!.sendRAWData(ESCUtil.boldOn(), null)


                    woyouService!!.printColumnsString(
//                "Moneda",
//                    "   " + /*context.getString(R.string.jine)*/ "Numero"
                        arrayOf("Number", "Prijs", "Number", "Prijs"),
                        intArrayOf(3, 3, 3, 3),
                        intArrayOf(0, 2, 0, 2), null
                    )
                    woyouService!!.setFontSize(24f, null)
                    woyouService!!.sendRAWData(ESCUtil.boldOn(), null)

                    val size = data.size
                    val colums = if (size % 2 == 0) size / 2 else (size / 2 + 1)
                    if (size != 0)
                        for (i in 0 until colums) {
                            val has2 = (colums + i) < size
                            val index2 = colums + i
                            woyouService!!.printColumnsString(
                                arrayOf(
                                    data[i].getNumber().replaceZero,
                                    data[i].money.toString().replaceZero,
                                    if (has2) "|" else "",
                                    if (has2) data[index2].getNumber().replaceZero else "",
                                    if (has2) data[index2].money.toString().replaceZero else ""

                                ), intArrayOf(5, 4, 1, 5, 4),
                                intArrayOf(0, 2, 1, 0, 2), null
                            )

                            if ((i - 40) % 50 == 0) woyouService!!.lineWrap(4, null)

                        }

                    woyouService!!.setFontSize(28f, null)
                    woyouService!!.lineWrap(1, null)
                    woyouService!!.printColumnsString(
                        arrayOf(
                            /*context.getString(R.string.zongjine_dot)*/"Total: ",
                            data.sumByDouble { it.money }.toString()
                        ), intArrayOf(2, 4),
                        intArrayOf(0, 0), null
                    )
                }

            woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
            woyouService!!.setFontSize(32f, null)
            woyouService!!.lineWrap(1, null)
            woyouService!!.printColumnsString(
                arrayOf(
                    /*context.getString(R.string.zongjine_dot)*/"Total: ",
                    dataO.filter { !it.isHeader }.sumByDouble { it.t.money }.toString()
                ), intArrayOf(2, 4),
                intArrayOf(0, 0), null
            )
            woyouService!!.printColumnsString(
                arrayOf(
                    /*context.getString(R.string.zongjine_dot)*/"lucky: ",
                    LotteryApp.getJiHao(context)
                ), intArrayOf(2, 4),
                intArrayOf(0, 0), null
            )
            woyouService!!.lineWrap(1, null)
            woyouService!!.setFontSize(26f, null)
            woyouService!!.printColumnsString(
                arrayOf(
//                    timeFormatter.format(ClockUtil.getCurrentTime(context)).replaceZero.replace(
//                        ".",
//                        ""
//                    )
                    timeNow + "(WiFi)"
                ),
                intArrayOf(1),
                intArrayOf(1),
                null
            )

            woyouService!!.lineWrap(5, null)

            woyouService!!.exitPrinterBufferWithCallback(true, callback)

        } catch (e: RemoteException) {
            e.printStackTrace()
            callback.onPrintResult(1, "")
        }
    }

    private fun getS(i: Int) = context.getString(i)

    /**
     * @param isCunGeng false=票  true=存根
     */
    private fun printADealData(deal: Order, isCunGeng: Boolean) {
        if (/*!BuildConfig.DEBUG*/true) {
            //getTime()
            val jihao = LotteryApp.getJiHao(context)
            woyouService!!.sendRAWData(ESCUtil.boldOn(), null)
            woyouService!!.lineWrap(1, null)
            woyouService!!.setAlignment(1, null)
            var biaoTi = ""
            if (deal.belongTo.contains("+S")){
                biaoTi = "WEGA DI NUMBER\n" + deal.belongTo.replace("S","S.evening")
            }else{
                biaoTi = LotteryApp.getTitle(deal.belongTo)
            }
            woyouService!!.printTextWithFont("$biaoTi\n\n", "BOLD", 40f, null)
            if (isCunGeng) {
                woyouService!!.setFontSize(30f, null)
                woyouService!!.printColumnsString(
                    arrayOf("(" +/* getS(R.string.dianzipiaocungen) + */"电子票存根" + ")"),
                    intArrayOf(1),
                    intArrayOf(1),
                    null
                )
            }
            woyouService!!.setAlignment(0, null)
            val storeName = SPUtils[context, "store_name", "Lucky"] as String
            woyouService!!.printTextWithFont("Name:", null, 32f, null)
            woyouService!!.printTextWithFont("$storeName\n", null, 32f, null)
            woyouService!!.setFontSize(28f, null)
            woyouService!!.printTextWithFont("Lucky:", null, 32f, null)
            woyouService!!.printTextWithFont("$jihao\n", null, 32f, null)
            woyouService!!.setFontSize(28f, null)
            woyouService!!.printText("Factura: ${deal.serialNumber.replaceZero}\n", null)
            woyouService!!.setFontSize(36f, null)
            woyouService!!.printText("Fecha: ${timeReplace(riQiFormatter.format(Date().time))}\n", null)
            woyouService!!.setFontSize(30f, null)
            woyouService!!.sendRAWData(aLineRaw, null)
            woyouService!!.printColumnsString(
                arrayOf(
                    "Number",
                    "Prijs", ""
                ),
                intArrayOf(3, 3, 2),
                intArrayOf(0, 0, 1),
                null
            )

            woyouService!!.setFontSize(34f, null)
//            deal.bets.sortedWith(Comparator<BetCountEntity> { o1, o2 ->
//                val t1 = (if (o1.pool) 0 else 100000) + o1.type * 10000 + o1.num
//                val t2 = (if (o2.pool) 0 else 100000) + o2.type * 10000 + o2.num
//                t2 - t1
//            }).forEach {
//                woyouService!!.printColumnsString(
//                    arrayOf(
//                        it.getNumber().replaceZero,
//                        it.money.toString().replaceZero,
//                        if (it.pool) "Pool" else ""
//                    ),
//                    intArrayOf(3, 3, 2),
//                    intArrayOf(1, 1, 1),
//                    null
//                )
//            }
            deal.bets.reversed().forEach {
//            deal.bets.forEach {
                woyouService!!.printColumnsString(
                    arrayOf(
                        it.getNumber().replaceZero,
                        it.money.toString().replaceZero,
                        if (it.pool) "Pool" else ""
                    ),
                    intArrayOf(3, 3, 2),
                    intArrayOf(0, 0, 1),
                    null
                )
            }

            woyouService!!.setFontSize(30f, null)
            woyouService!!.sendRAWData(aLineRaw, null)

            woyouService!!.setFontSize(34f, null)
            woyouService!!.printText(
                /*context.getString(R.string.zongjine_dot)*/"Total Naf: "
                        + deal.getTotal().toString().replaceZero + "\n\n",
                null
            )
            woyouService!!.setAlignment(1, null)
            woyouService!!.setFontSize(26f, null)
            woyouService!!.printText(
                deal.timeStrAuto.replace("0", "O")
                    .replace(".", "") + "(WiFi)", null
            )

            val js = "{\"mac\":\"$jihao\",\"or\":\"${deal.serialNumber}\"}"
            woyouService!!.setAlignment(1, null)
            woyouService!!.printQRCode(js, 7, 3, null)
            woyouService!!.lineWrap(1, null)
            //默认行高
            woyouService!!.sendRAWData(byteArrayOf(0x1B, 0x32, 0xC4.toByte()), null)
            woyouService!!.lineWrap(3, null)
        }
    }

    /**
     * 获取当前服务器时间并格式化
     * @param patterns 格式化规则
     * @param timeCallBack 时间处理回调
     */
    fun getTime(patterns: String, timeCallBack: TimeCallBack) {
        val timestampNow = getTimeStampNow()
        if (timestampNow > 0L) {
            //按照参数给的时间格式话，以西四区时间格式化
            TimeZone.getDefault().getDisplayName(true, TimeZone.SHORT)
            val format = SimpleDateFormat(patterns)
            format.timeZone = TimeZone.getTimeZone("GMT-4")

            //展示出时间差
            timeCallBack.onSuccess(format.format(Date(timestampNow)))
        } else {
            timeCallBack.onError("时间同步失败，请稍后再试")
        }
    }

    /**
     * 获取当前时间戳（服务器时间）
     */
    fun getTimeStampNow(): Long {
        //上次时间同步时取到的服务器时间
        val serviceTime =
            SPUtils.get(LotteryApp.context, Constants.SP_SYNC_currentTimeMillis, 0L) as Long
        //上次时间同步时记录的本地时间点（用来计算与现在的时间差）
        val elapsedRealTime =
            SPUtils.get(LotteryApp.context, Constants.SP_SYNC_elapsedRealTime, 0L) as Long
        return if (serviceTime > 0L && elapsedRealTime > 0L) {
            //上次同步时到现在的时间差
                val temp = SystemClock.elapsedRealtime();
            val timePass = SystemClock.elapsedRealtime() - elapsedRealTime
            //修正，得到当前时间点服务器的正确时间
            timePass + serviceTime
        } else {
            0L
        }
    }


    /**
     *  @param printType:  0：仅票   1：票+存根   2：仅存根
     */
    fun printADeal(deal: Order, printType: Int, callback: ICallback) {
        when (printType) {
            0 -> {
                printDealPrivate(deal, printType, callback)
            }
            1 -> {
                printDealPrivate(deal, 0, null)
                Flowable.timer(5000, TimeUnit.MILLISECONDS, Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe {
                        printDealPrivate(deal, 2, callback)
                    }
            }
            2 -> {
                printDealPrivate(deal, printType, callback)
            }
        }

    }

    /**
     * @param printType:  0：仅票   1：票+存根   2：仅存根
     */
    private fun printDealPrivate(deal: Order, printType: Int, callback: ICallback?) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }
        try {
            woyouService!!.enterPrinterBuffer(true)
            when (printType) {
                0 -> printADealData(deal, false)
                2 -> printADealData(deal, true)
            }
            woyouService!!.exitPrinterBufferWithCallback(true, callback)
        } catch (e: RemoteException) {
            e.printStackTrace()
        }
    }


    /**
     * printType:0：仅票 1：票+存根 2：仅存根
     */
    @SuppressLint("CheckResult")
    fun printWinDeals(deals: MutableList<DealEntity>, callback: ICallback) {
        if (woyouService == null) {
            Toast.makeText(context, "服务已断开!", Toast.LENGTH_LONG).show()
            return
        }
        try {

            Flowable.just("")
                .subscribeOn(Schedulers.newThread())
                .map {
                    deals.forEachIndexed { index, dealEntity ->
                        woyouService!!.enterPrinterBuffer(true)
//                        printADealData(dealEntity, true)
                        woyouService!!.exitPrinterBufferWithCallback(
                            true,
                            if (index == deals.size - 1) callback else null
                        )
                        Thread.sleep(4000)
                    }
                }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    XLog.e("")
                }

        } catch (e: RemoteException) {
            e.printStackTrace()
        }


    }


    private val aLineRaw = byteArrayOf(
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x2D,
        0x0A
    )
    private val aDoubleLineRaw = byteArrayOf(
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x3D,
        0x0A
    )

    companion object {
        private const val SERVICE_PACKAGE = "woyou.aidlservice.jiuiv5"
        private const val SERVICE_ACTION = "woyou.aidlservice.jiuiv5.IWoyouService"
        val instance: AidlUtil by lazy { AidlUtil() }
    }


}

private val String.replaceZero: String
    get() {
        return replace("0", "O")
    }

fun timeReplace(timeString: String):String {
    val l = timeString.split('-')
    val resultStr = l[0] + "-" + "**" + "-" + l[2]
    val monthStr = when(l[1]){
        "01" -> "Jan"
        "02" -> "Feb"
        "03" -> "Mar"
        "04" -> "Apr"
        "05" -> "May"
        "06" -> "Jun"
        "07" -> "Jul"
        "08" -> "Aug"
        "09" -> "Sep"
        "10" -> "Oct"
        "11" -> "Nov"
        else -> "Dec"
    }
    return resultStr.replace("**",monthStr)
}